import { type ApiDetail, getApiDetail } from '@/api/api-manage/detail'

export default function useApiDetail() {
  const data = ref<ApiDetail>({
    id: 0,
    deptId: 0,
    apiName: '',
    apiType: '',
    apiCatalog: '',
    apiAuth: '',
    encryptionType: '',
    apiDesc: '',
    requestProtocol: '',
    requestMethod: '',
    requestPath: '',
    serverProdPath: '',
    serverTestPath: '',
    serverUri: '',
    requestTimeOut: 0,
    serverNetworkType: '',
    serverContentType: '',
    responseType: '',
    responseExampleValue: '',
    checkStatus: '',
    enabledStatus: '',
    checkBy: '',
    checkTime: '',
    callFreq: 0,
    apiIconPth: '',
    updateTime: '',
    algorithmBasic: '',
    version: '',
  })
  const [loading, toggleLoading] = useToggle(false)

  async function getData(id: string) {
    toggleLoading(true)
    const res = await getApiDetail(id).finally(() => {
      toggleLoading(false)
    })

    data.value = res.data
  }

  return { data, loading, getData }
}
